#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->listWidget->addItem("donk");
    ui->listWidget->addItem("faker");
    ui->listWidget->addItem("dog");
    ui->listWidget->addItem(new QListWidgetItem("cat"));

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current!=nullptr&&previous!=nullptr)
    {
        qDebug()<<"现在选择的"<<current->text()<<"之前选择的:"<<previous->text();
    }
}

void Widget::on_pushButton_add_clicked()
{
    const QString& s = ui->lineEdit->text();
    if(s.isEmpty())
    {
        return;
    }
    ui->listWidget->addItem(s);
}

void Widget::on_pushButton_delete_clicked()
{
    int cow = ui->listWidget->currentRow();
    ui->listWidget->takeItem(cow);
}
